Assgent
Files:Tags: No tags.function x = string_to_sound(keys,Fs,T,Tpause)
t = (0:fix(T*Fs)).'/Fs ;
zp = zeros(fix(Tpause*Fs/2),1) ;
x = [];
for r = 1:length(keys(:))
char = keys(r);
x = [x ; zp ; cos(2*pi*get_frequency_1(char)*t) + cos(2*pi*get_frequency_2(char)*t) ; zp];
end
endx = [x, pause, cos(26*pi*char*t)+cos(22*pi*(char-50)*t), pause]sound_normalized = sound / (max(abs(sound)));
audiowrite("sound.wav", sound_normalized, Fs);
They did this, sp we can recover it i guess%Build script to beep-boop (UMDCTF2023, author: Assgent)
%{
A flag was encoded into a sound file using the script below.
Analyze the script and reverse-engineer the flag!
%}
close
clear all
flag = fileread("flag.txt");
Fs = 8192;
sound = string_to_sound(flag, Fs, 1, 0.5);
sound_normalized = sound / (max(abs(sound)));
audiowrite("sound.wav", sound_normalized, Fs);
function freq = get_frequency_1(char)
freq = char * 13;
end
function freq = get_frequency_2(char)
freq = (char - 50) * 11;
end
% Fs is the samples/sec.
% T is the duration of each key. (in seconds)
% Tpause is the pause between keys. (in seconds)
function x = string_to_sound(keys,Fs,T,Tpause)
t = (0:fix(T*Fs)).'/Fs ;
zp = zeros(fix(Tpause*Fs/2),1) ;
x = [];
for r = 1:length(keys(:))
char = keys(r);
x = [x ; zp ; cos(2*pi*get_frequency_1(char)*t) + cos(2*pi*get_frequency_2(char)*t) ; zp];
end
end[x, Fs] = audioread('sound.wav');
fc = 500; % frekuensi cutoff (Hz)
[b, a] = butter(4, fc/(Fs/2), 'high');
x_filtered = filter(b, a, x);
threshold = 0.2;
x_noisy = abs(x_filtered);
x_noisy(x_noisy < threshold) = 0;
T = 1/Fs; %
N = length(x_noisy); %
t = (0:N-1)*T; %
f = (0:N-1)*(Fs/N); %
freq1 = zeros(length(t),1);
freq2 = zeros(length(t),1);
for n = 1:length(t)
s = x_noisy(n);
if s ~= 0
freq1(n) = round(s/13);
freq2(n) = round(s/11) + 50;
end
end
flag = '';
for n = 1:length(freq1)
if freq1(n) ~= 0 && freq2(n) ~= 0
c = char([freq1(n), freq2(n)]);
flag = strcat(flag, c);
end
end
disp(flag); (edited)[x, Fs] = audioread('sound.wav');
fc = 500; % frekuensi cutoff (Hz)
[b, a] = butter(4, fc/(Fs/2), 'high');
x_filtered = filter(b, a, x);
threshold = 0.2;
x_noisy = abs(x_filtered);
x_noisy(x_noisy < threshold) = 0;
T = 1/Fs; %
N = length(x_noisy); %
t = (0:N-1)*T; %
f = (0:N-1)*(Fs/N); %
freq1 = zeros(length(t),1);
freq2 = zeros(length(t),1);
for n = 1:length(t)
s = x_noisy(n);
if s ~= 0
freq1(n) = round(s/13);
freq2(n) = round(s/11) + 50;
end
end
flag = '';
for n = 1:length(freq1)
if freq1(n) ~= 0 && freq2(n) ~= 0
c = char([freq1(n), freq2(n)]);
flag = strcat(flag, c);
end
end
disp(flag); (edited)%Build script to beep-boop (UMDCTF2023, author: Assgent)
%{
A flag was encoded into a sound file using the script below.
Analyze the script and reverse-engineer the flag!
%}
close
clear all
flag = fileread("flag.txt");
Fs = 8192;
sound = string_to_sound(flag, Fs, 1, 0.5);
sound_normalized = sound / (max(abs(sound)));
audiowrite("sound.wav", sound_normalized, Fs);
function freq = get_frequency_1(char)
freq = char * 13;
end
function freq = get_frequency_2(char)
freq = (char - 50) * 11;
end
% Fs is the samples/sec.
% T is the duration of each key. (in seconds)
% Tpause is the pause between keys. (in seconds)
function x = string_to_sound(keys,Fs,T,Tpause)
t = (0:fix(T*Fs)).'/Fs ;
zp = zeros(fix(Tpause*Fs/2),1) ;
x = [];
for r = 1:length(keys(:))
char = keys(r);
x = [x ; zp ; cos(2*pi*get_frequency_1(char)*t) + cos(2*pi*get_frequency_2(char)*t) ; zp];
end
end close
clear all
flag = "UMDCTF{test_flag}";
Fs = 8192;
sound = string_to_sound(flag, Fs, 1, 0.5);
sound_normalized = sound / (max(abs(sound)));
audiowrite("sound.wav", sound_normalized, Fs);
function freq = get_frequency_1(char)
freq = char * 13;
end
function freq = get_frequency_2(char)
freq = (char - 50) * 11;
end
% Fs is the samples/sec.
% T is the duration of each key. (in seconds)
% Tpause is the pause between keys. (in seconds)
function x = string_to_sound(keys,Fs,T,Tpause)
t = (0:fix(T*Fs)).'/Fs ;
zp = zeros(fix(Tpause*Fs/2),1) ;
x = [];
for r = 1:length(keys(:))
char = keys(r);
x = [x ; zp ; cos(2*pi*get_frequency_1(char)*t) + cos(2*pi*get_frequency_2(char)*t) ; zp];
end
endclear all
flag = "UMDCTF{test_flag}";
Fs = 8192;
sound = string_to_sound(flag, Fs, 1, 0.5);
sound_normalized = sound / (max(abs(sound)));
audiowrite("sound.wav", sound_normalized, Fs);
disp(max(abs(sound)));
function freq = get_frequency_1(char)
freq = char * 13;
end
function freq = get_frequency_2(char)
freq = (char - 50) * 11;
end
% Fs is the samples/sec.
% T is the duration of each key. (in seconds)
% Tpause is the pause between keys. (in seconds)
function x = string_to_sound(keys,Fs,T,Tpause)
t = (0:fix(T*Fs)).'/Fs ;
zp = zeros(fix(Tpause*Fs/2),1) ;
x = [];
for r = 1:length(keys(:))
char = keys(r);
x = [x ; zp ; cos(2*pi*get_frequency_1(char)*t) + cos(2*pi*get_frequency_2(char)*t) ; zp];
end
endclear all
flag = "UMDCTF{test_flag}";
Fs = 8192;
sound = string_to_sound(flag, Fs, 1, 0.5);
sound_normalized = sound / (max(abs(sound)));
audiowrite("sound.wav", sound_normalized, Fs);
disp(max(abs(sound)));
function freq = get_frequency_1(char)
freq = char * 13;
end
function freq = get_frequency_2(char)
freq = (char - 50) * 11;
end
% Fs is the samples/sec.
% T is the duration of each key. (in seconds)
% Tpause is the pause between keys. (in seconds)
function x = string_to_sound(keys,Fs,T,Tpause)
t = (0:fix(T*Fs)).'/Fs ;
zp = zeros(fix(Tpause*Fs/2),1) ;
x = [];
for r = 1:length(keys(:))
char = keys(r);
x = [x ; zp ; cos(2*pi*get_frequency_1(char)*t) + cos(2*pi*get_frequency_2(char)*t) ; zp];
end
end t is just range(0, 1, 1/8193) (edited)Fs = 8192;
function freq = get_frequency_1(char)
freq = char * 13;
end
function freq = get_frequency_2(char)
freq = (char - 50) * 11;
end
function x = string_to_sound(keys,Fs,T,Tpause)
t = (0:fix(T*Fs)).'/Fs ;
zp = zeros(fix(Tpause*Fs/2),1) ;
x = [];
for r = 1:length(keys(:))
char = keys(r);
x = [x ; zp ; cos(2*pi*get_frequency_1(char)*t) + cos(2*pi*get_frequency_2(char)*t) ; zp];
end
end
% our script
[y, Fs] = audioread('sound.wav');
y = y * 2;
for r = 0:50
sub = y(r*12289+1:(r+1)*12289);
for char = 32:126
x = string_to_sound(char,Fs,1,0.5);
if sum(abs(sub(2048:2058)-x(2048:2058))) < 0.001
disp(char);
end
end
end (edited)